cmake_minimum_required(VERSION 3.8)
project(Macro)

function(print_line)
	message(STATUS "==========")
endfunction()


macro(macro1)
	message(STATUS "macro1 called")
endmacro(macro1)

print_line()
macro1()
MACRO1()

set(Var1 "Var1: init")

macro(macro2)
	set(Var1 "Var1: set Var1 in macro2")
	message(STATUS "Var1 in macro2 = ${Var1}")
endmacro()

print_line()
message(STATUS "before call macro2: Var1 = ${Var1}")
macro2()
message(STATUS "after call macro2: Var1 = ${Var1}")

macro(macro3 arg1 arg2)
	message(STATUS "arg1 = ${arg1}")
	message(STATUS "arg2 = ${arg2}")
	message(STATUS "number of arguments = ${ARGC}")
	message(STATUS "arg0 = ${ARGV0}, arg1 = ${ARGV1}")
	message(STATUS "arguments list = ${ARGV}")
	message(STATUS "ARGN = ${ARGN}")
	message(STATUS "ARGV2 = ${ARGV2}")
endmacro()

print_line()
macro3("aaa" "bbb" "ccc" "ddd")


function(func4)
	if(ARGV1)
		message(STATUS "ARGV1 = ${ARGV1}")
	endif()
	if(DEFINED ARGV2)
		message(STATUS "ARGV2 = ${ARGV2}")
	endif()
	if(ARGC GREATER 2)
		message(STATUS "ARGC GREATER 2")
	else()
		message(STATUS "ARGC NOT GREATER 2")
	endif()
	foreach(var IN LISTS ARGN)
		message(STATUS "var = ${var}")
	endforeach()
endfunction(func4)


print_line()
func4("aaa" "bbb" "ccc" "ddd")

macro(macro4)
	if(ARGV1)
		message(STATUS "ARGV1 = ${ARGV1}")
	endif()
	if(DEFINED ARGV2)
		message(STATUS "ARGV2 = ${ARGV2}")
	endif()
	if(ARGC GREATER 2)
		message(STATUS "ARGC GREATER 2")
	else()
		message(STATUS "ARGC NOT DEFINED")
	endif()
	foreach(var IN LISTS ARGN)
		message(STATUS "var = ${var}")
	endforeach()
	set(list_var "${ARGN}")
	foreach(var IN LISTS list_var)
		message(STATUS "var in list_var = ${var}")
	endforeach()
endmacro()

print_line()
macro4("aaa" "bbb" "ccc" "ddd")


macro(macro5)
	foreach(arg IN LISTS ARGN)
		message(STATUS "arg = ${arg}")
	endforeach()
endmacro()

function(func5)
	macro5(xx yy zz)
endfunction()

print_line()
func5("aa" "bb" "cc")
